
import React from 'react';
import * as THREE from 'three';
import Controller from "../Controller";

/** 网格 */
export default function useGridHelper(controller: Controller) {

    const scene = controller.useMemo(s => s.scene, [])

    const model = controller.useMemo(s => s.model, [])

    React.useEffect(() => {

        if (
            !scene ||           // 场景不存在
            model === 'preview' // 只读模式
        ) return;

        // 创建网格
        const gridHelper = new THREE.GridHelper(1000, 500);
        scene.add(gridHelper);

        return () => {
            gridHelper.removeFromParent();
        }
    }, [controller, model, scene])
}